package com.keray.web.push.store;

import com.keray.web.push.MessageType;
import com.keray.web.push.worker.SocketWorker;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;

import java.util.HashMap;
import java.util.Map;

/**
 * @author by keray
 * date:2021/7/26 11:22 上午
 */
@Configuration
public class WorkerStore implements BeanPostProcessor {

    public static final Map<MessageType, SocketWorker> MAP = new HashMap<>();

    @Override
    @Nullable
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof SocketWorker) {
            MAP.put(((SocketWorker) bean).activeType(), (SocketWorker) bean);
        }
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }
}
